/**
 * @(#)ApkConfigController.java 2017年03月1日
 * Copyright(C) 2017 ZHEXIN IT CO.,LTD. All rights reserved.
 */
package org.jsbd.boss.action;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.jsbd.boss.domian.MiguMusicConfigBean;
import org.jsbd.boss.service.IMiguMusicConfigService;
import org.jsbd.boss.common.DataGridModel;
import org.jsbd.boss.common.ResponseMapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@RequestMapping("/miguMusicConfig")
public class MiguMusicConfigController{

	private static final Logger LOGGER=LoggerFactory.getLogger(MiguMusicConfigController.class);
	
	@Autowired
	private IMiguMusicConfigService miguMusicConfigService;

	/**
	 * 列表页面
	 * 
	 * @param model
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "listModel")
	public String showMiguMusicConfigList(Model model) throws Exception {
		return "/miguMusicConfig/miguMusicConfigList";
	}

	@RequestMapping(value = "saveMiguMusicConfig")
	@ResponseBody
	public Object saveMiguMusicConfig(MiguMusicConfigBean miguMusicConfig){
		miguMusicConfigService.saveMiguMusicConfig(miguMusicConfig);
		return ResponseMapUtils.responseSuccess();
	}

	@RequestMapping(value = "updateMiguMusicConfig")
	@ResponseBody
	public Object updateMiguMusicConfig(MiguMusicConfigBean miguMusicConfig){
		if (miguMusicConfig.getId() == null) {
			return ResponseMapUtils.responseFail("参数缺失，请确认参数再提交");
		}
		
		MiguMusicConfigBean condition=new MiguMusicConfigBean();
		condition.setId(miguMusicConfig.getId());
		MiguMusicConfigBean temp=miguMusicConfigService.getMiguMusicConfig(condition);
		if(temp==null){
			return ResponseMapUtils.responseFail("记录未找到,请重试");
		}
		
		miguMusicConfigService.updateMiguMusicConfig(miguMusicConfig);
		return ResponseMapUtils.responseSuccess();
	}
	
	@RequestMapping(value = "updateMiguMusicStatus")
	@ResponseBody
	public Object updateMiguMusicStatus(MiguMusicConfigBean miguMusicConfig){
		if (miguMusicConfig.getId() == null||miguMusicConfig.getStatus()==null) {
			return ResponseMapUtils.responseFail("参数缺失，请确认参数再提交");
		}
		miguMusicConfigService.updateMiguMusicStatus(miguMusicConfig);
		return ResponseMapUtils.responseSuccess();
	}

	@RequestMapping(value = "getMiguMusicConfig")
	@ResponseBody
	public MiguMusicConfigBean getMiguMusicConfig(MiguMusicConfigBean miguMusicConfig) throws Exception {
		return miguMusicConfigService.getMiguMusicConfig(miguMusicConfig);
	}

	@RequestMapping(value = "getMiguMusicConfigList")
	@ResponseBody
	public List<MiguMusicConfigBean> getMiguMusicConfigList(MiguMusicConfigBean miguMusicConfig) throws Exception {
		return miguMusicConfigService.getMiguMusicConfigList(miguMusicConfig);
	}

	@RequestMapping(value = "getMiguMusicConfigListPage")
	@ResponseBody
	public Map<String, Object> getMiguMusicConfigListPage(DataGridModel page, MiguMusicConfigBean miguMusicConfig) throws Exception {
		String sname = miguMusicConfig.getSname();
		if (StringUtils.isNotBlank(sname)) {
			String[] snames = sname.split(" ");
			List<String> keywords = new ArrayList<>();
			for (String keyword : snames) {
				keywords.add(keyword);
			}
			miguMusicConfig.setKeywords(keywords);
		}
		return miguMusicConfigService.getMiguMusicConfigListPage(page, miguMusicConfig);
	}
	
	@RequestMapping(value = "deleteMiguMusicConfig")
	@ResponseBody
	public Map<String, Object> deleteMiguMusicConfig(MiguMusicConfigBean miguMusicConfig) throws Exception {
		miguMusicConfigService.deleteMiguMusicConfig(miguMusicConfig);
		return ResponseMapUtils.responseSuccess();
	}
	

}
